﻿Imports System.Windows.Forms
Imports C1.C1Zip
Public Class dlgZip
    Private m_FileName As String
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub cmbSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSet.Click
        Dim _appTitle As String = "C1Zip Demo"      ' the caption
        Dim _escape As Boolean = False              ' user hit escape
        Dim _cancel As Boolean = False              ' user wants to cancel
        ' show file open dialog
        Dim sf As SaveFileDialog = New SaveFileDialog()
        sf.DefaultExt = "zip"
        sf.Filter = "Zip Files (*.zip)|*.zip"
        If sf.ShowDialog() <> Windows.Forms.DialogResult.OK Then Return
        m_FileName = sf.FileName
        Me.TextBox1.Text = m_FileName

    End Sub

    Private Sub dlgZip_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub cmbZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbZ.Click
        If m_FileName <> "" Then

            Dim filses(5) As String
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermet\" & "stage2.inp") Then
                filses(0) = CAermod.Path.ModelsPath() & "Aermet\" & "stage2.inp"
            End If
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermet\" & "stage3.inp") Then
                filses(1) = CAermod.Path.ModelsPath() & "Aermet\" & "stage3.inp"
            End If
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermet\" & "SF.OQA") Then
                filses(2) = CAermod.Path.ModelsPath() & "Aermet\" & "SF.OQA"
            End If
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermet\" & "UA.OQA") Then
                filses(3) = CAermod.Path.ModelsPath() & "Aermet\" & "UA.OQA"
            End If

            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermet\" & "OS.OQA") Then
                filses(4) = CAermod.Path.ModelsPath() & "Aermet\" & "OS.OQA"

            End If

            AddFileList(filses, 0)
        End If

    End Sub
    ' add a list of files to the zip file, keeping the specified pathLevels
    Private Sub AddFileList(ByVal files() As String, ByVal pathLevels As Integer)
        Dim _zipfile As C1ZipFile = New C1ZipFile()
        ' create a new empty zip file
        _zipfile.Create(m_FileName)
        ' keep track of errors and time execution 
        Dim err As String = ""
        Dim start As Long = DateTime.Now.Ticks

        ' add files
        Dim file As String
        For Each file In files
            If file <> "" Then
                ' add the file 
                Dim x As Exception
                Try
                    Me.Label2.Text = "正在打包" & file
                    _zipfile.Entries.Add(file, pathLevels)
                    Application.DoEvents()
                Catch x
                    Me.Label2.Text = x.Message
                    Exit Sub
                End Try
            End If
        Next
        Me.Label2.Text = "打包完毕"
    End Sub
End Class
